home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <math.h>
- #include <graphics.h>
-
-
- void main(void)
- {
- int i,j,k,l;
- int height, height2;
- int color;
- unsigned char x,y,z;
- int window, level;
- unsigned char bubblemass[70][70][70];
- unsigned char bubble[21][21][21];
- int graphdriver, graphmode, grerror;
-
-
-
- /*GET WINDOW AND LEVEL FROM USER*/
-
- window = -1;
- level = -1;
-
- while((window > 255)||(window <= 0))
- {
- printf("Window(0-255):");
- scanf("%d",&window);
- }
-
- while((level < (window/2))||(level > (255 - window/2)))
- {
- printf("Level(%d-%d):", window/2, (255 - window/2 - 1));
- scanf("%d",&level);
- }
-
-
- /*MAKE BUBBLE*/
-
- for(i=-10; i < 11; i++)
- {
- height = ceil(10*sin(acos((double)i/10)));
- if(height != 0)
- for(j=-height; j < height+1; j++)
- {
- height2 = ceil(height*sin(acos((double)j/height)));
- if(height2 !=0)
- for(k=-height2; k < height2+1; k++)
- bubble[i+10][j+10][k+10] = 1;
- }
-
- }
-
-
- /*INITIATE BUBBLE MASS*/
-
- for(i=0; i < 70; i++)
- for(j=0; j < 70; j++)
- for(k=0; k < 70; k++)
- bubblemass[i][j][k] = 0;
-
-
- /*CREATE BUBBLE MASS*/
-
- for(l=0; l < 1400; l++)
- {
- x = (unsigned char)(((double)(rand())*30/
- (double)RAND_MAX) + 10);
- y = (unsigned char)(((double)(rand())*30/
- (double)RAND_MAX) + 10);
- z = (unsigned char)(((double)(rand())*30/
- (double)RAND_MAX) + 10);
-
- for(i=0; i < 21; i++)
- for(j=0; j < 21; j++)
- for(k=0; k < 21; k++)
- if(bubble[i][j][k] == 1)
- if(bubblemass[x+i][y+j][z+k] < 255)
- bubblemass[x+i][y+j][z+k] ++;
- }
-
-
- /*PLOT IMAGE WITH WINDOWING AND LEVELING*/
-
- graphdriver = VGA256;
- graphmode = 0;
- initgraph( &graphdriver, &graphmode, "");
- grerror = graphresult();
- if(grerror)
- {
- closegraph();
- printf("Error Initializing Graphics Mode.\n");
- exit(1);
- }
-
- while(!kbhit())
- {
- for(i=0; i < 70; i++)
- for(j=0; j < 70; j++)
- for(k=0; k < 70; k++)
- {
- color = (int)bubblemass[i][j][k] - (level - window/2);
- if(color < 0)
- color = 0;
- if(color > window)
- color = 15;
- else color = (int)floor((double)color/(double)window*15.0);
- putpixel(j, k, color+16);
- }
-
- }
-
- getch();
- closegraph();
-
- }
-